package gof.observe;

import java.util.ArrayList;
import java.util.List;

/**
 * TODO
 * 2020-11-03 10:49
 */
public class WeatherData implements Subject {

    List<Observer> Observers;
    Integer Temprature;
    Integer Humidity;
    Integer Pressure;

    public WeatherData(){
        Observers = new ArrayList<Observer>();
    }

    @Override
    public void registerObserver(Observer observer) {
        Observers.add(observer);
    }

    @Override
    public void deleteObserver(Observer observer) {
        Observers.remove(observer);
    }

    @Override
    public void notifyObserver() {
        for (Observer observer : Observers) {
            observer.update(this.Temprature, this.Humidity, this.Pressure);
        }
    }

    public void measurementChanged(Integer Temprature, Integer Humidity, Integer Pressure){
        this.Temprature = Temprature;
        this.Humidity = Humidity;
        this.Pressure = Pressure;
        notifyObserver();
    }

    public static void main(String[] args) {
        WeatherData weatherData = new WeatherData();
        Display01 display01 = new Display01(weatherData);
        Display02 display02 = new Display02(weatherData);
        weatherData.measurementChanged(100,200,300);
        weatherData.deleteObserver(display02);
        weatherData.measurementChanged(200,100,300);
    }
}
